// pages/change/change.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    index:1,num:1,
    index1:2,num1:1,
    picker: ['财务部', '销售部', '开发部', '人事部', '后勤部'],
    job:['实习生','员工','总经理']
  },
  AgeChange(e){
    this.setData({
      age: e.detail.value
    })
  },
  DateChange(e) {
    this.setData({
      date: e.detail.value
    })
  },
  PickerChange(e) {
    console.log(e);
    this.setData({
      index: e.detail.value
    })
  },
  PickerChange1(e) {
    console.log(e);
    this.setData({
      num: e.detail.value
    })
  },
  PickerChange2(e) {
    console.log(e);
    this.setData({
      index1: e.detail.value
    })
  },
  PickerChange3(e) {
    console.log(e);
    this.setData({
      num1: e.detail.value
    })
  },
  forsubmit:function(e){
    var msg = e.detail.value;
    // console.log("oldname:"+this.data.orpicker[this.data.index])
    // console.log("oldlname:" +this.data.job[this.data.num])
    // console.log("newname:" +this.data.picker[this.data.index1])
    // console.log("newlname:" +this.data.job[this.data.num1])
    // console.log(msg.empno)
    // console.log(msg.ename)
    // console.log(msg.oldjob)
    // console.log(msg.newjob)
    // console.log(msg.reason)
    
    if (msg.ename == ""){
      wx.showToast({
        title: '姓名不能为空',
        icon: 'none'
      })
    } else if (msg.empno == ""){
      wx.showToast({
        title: '工号不能为空',
        icon: 'none'
      })
    } else if (msg.oldjob == "") {
      wx.showToast({
        title: '当前涉及的领域不能为空',
        icon: 'none'
      })
    } else if (msg.newjob == "") {
      wx.showToast({
        title: '申请涉及的领域不能为空',
        icon: 'none'
      })
    } else if (msg.reason == "") {
      wx.showToast({
        title: '原因不能为空',
        icon: 'none'
      })
    }else{
      if (this.data.job[this.data.num1] === '员工') {
        var newlevel = 'T2'
      } else {
        var newlevel = 'T3'
      }
      wx.request({
        url: 'http://192.168.1.6:8080/WeChatJSON//insertChangeInfo',
        data:{
          empno: msg.empno,                               //工号
          ename: msg.ename,                               //姓名
          ordname: this.data.orpicker[this.data.index],   //原所在部门名称
          orjob: msg.oldjob,                              //原涉及的领域职业
          newdname: this.data.picker[this.data.index1],   //申请的部门名称
          newjob: msg.newjob,                             //申请的领域职业
          newlevel: newlevel,                             //申请的职位等级
          reason: msg.reason,                             //原因
          oldlname: this.data.job[this.data.num]          //原职位等级的名称
        },
        method:'GET',
        header:{
          'content-type': 'application/json'
        },
        success:function(res){
          console.log(res)
          var msg = res.data;
          if (msg === '申请成功') {
            wx.showToast({
              title: msg,
              icon: 'success'
            })
            setTimeout(function () {
              wx.navigateBack({
              })
            }, 1500)
          }else{
            wx.showToast({
              title: msg,
              icon: 'none'
            })
          }
        }
      })
    }


  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    if(options.level === 'T3'){
      this.setData({
        dable: false,
        index: 0, num: 0,
        index1: 2, num1: 1,
        picker: ['财务部', '销售部', '开发部', '人事部', '后勤部'],
        orpicker: [options.dname],
        job: ['员工', '总经理']
      })
    }else{
      this.setData({
        dable:true,
        ename:options.ename,
        empno:options.empno,
        jobname: options.jobname,
        index:0,num:0,
        index1: 2, num1: 0,
        picker: ['财务部', '销售部', '开发部', '人事部', '后勤部'],
        orpicker:[options.dname],
        job: ['员工']
      })
    }
  },
})